<script>

$('#getOrderRow').click(function(){
	$.post('{{urlfor "ScreeningController.Add"}}', function(j) {
		if(j.code == 0) {
			receiveFormData(j.data)
		} else {
			layer.msg(j.msg)	
		}
	}, 'json');	
});


function receiveFormData(d) {
	if(!d) return false;
	
	for (var key in d){
		 val = d[key]
		 if(key == "Sex") {
			 $('input[name="Sex"]').each(function(){ if($(this).attr("value") == val) { $(this).prop("checked", true) }  });
		 }else if(key =="address") {
			 //address = val.split("-")
			 //addressInit('cmbProvince', 'cmbCity', 'cmbArea',"", (address[0]?address[0]:''), (address[1]?address[1]:''), (address[2]?address[2]:''));
		 }else{
			$("#"+key).val(val)
		 }
	 }
	 $('select').trigger('changed.selected.amui');
}

$('#SchoolId').on('change', function(){
	$('#SchoolName').val($(this).find(':selected').text())
});

$(function(){
	$selected = $('#SchoolId');
	$selected.val({{.m.SchoolId}})
	$selected.trigger('changed.selected.amui');
	
	$('input[value="{{.m.Sex}}"]').prop('checked', true);
	
});

$("#doMySubmit").validator({
  submit: function() {
	if(this.isFormValid()) {
		var that = $("#doMySubmit")
		var submitBtn = that.find('button[type="submit"]')
		if(submitBtn.hasClass('am-disabled')){
			return false;
		}	
		submitBtn.addClass('am-disabled');
		$.ajax({
			url: that.attr("action")
			, type: 'post'
			, data: that.serialize()
			, dataType: 'json'
			, success: function (response) {
				layer.msg(response.msg);
				if (response.code === 0) {
					setTimeout(function () {
						submitBtn.removeClass('am-disabled');
						$("#doMySubmit")[0].reset();
					}, 1000);
				} else {
					submitBtn.removeClass('am-disabled');
				}
			}
			, error: function (error) {
				submitBtn.removeClass('am-disabled');
				layer.msg('数据提交失败！');
			}
		});
	}
	return false;
  }
});


</script>